var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  getAddressList:function(e){
    var that = this;

    app.getUserToken(function (err, token) {
      wx.request({
        url: app.globalData.url +'/index.php?_m=shop/customers_address/listing',
        header: {
          'content-type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        data: { auth_token: token },
        success: (res) => {
          if (res.data.status == 401) {
            // 清空授权token
            app.globalData.token = null
            wx.removeStorageSync('token')
            that.getAddressList();
          } else if (res.data.code == 0) {
           
            that.setData({
              list: res.data.data
            })
          }
        },
        fail: (res) => {
          wx.showToast({
            title: '获取借口失败',
            duration: 2000
          })
        }
      })

    })

  },

  addAddress:function(e){
    wx.navigateTo({
      url: '../addAddress/addAddress'
    })
  },

  editaddress:function(e){
    
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url:'../editAddress/editAddress?id='+id
    })
  },

  onLoad: function (options) {
    this.getAddressList();
  },
  onShareAppMessage: function () {
    app.globalData.uid = app.globalData.uid || wx.getStorageSync('uid') || 0;
    return {
      title: '深圳智汇创想科技有限责任公司员工福利购!',
      path: '/pages/index/index?fid=' + app.globalData.uid
    }
  }
})